package com.zf.mo.mock;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

class MockServiceTest2 {

    @Mock
    private MockService mockService;
    @Spy
    private MockService spy;

    @BeforeEach
    void setUp(){
        MockitoAnnotations.openMocks(this);
    }

    @Test
    void test() {
       // MockService mockService = Mockito.mock(MockService.class);
        when(mockService.getStr1()).thenReturn("zhoufly");
        when(mockService.getStr2()).thenCallRealMethod();
        System.out.println(mockService.getStr1());
        System.out.println(mockService.getStr2());
    }
    @Test
    void test1(){
//        MockService spy = Mockito.spy(MockService.class);
        assertThat(spy.getStr1()).isEqualTo("getStr1");
        assertThat(spy.getStr2()).isEqualTo("getStr2");
        when(spy.getStr1()).thenReturn("zhoufly");
        assertThat(spy.getStr1()).isEqualTo("zhoufly");
        assertThat(spy.getStr2()).isEqualTo("getStr2");
    }



}